from django.core.management.base import BaseCommand
from product.service.product_generate_service import ProductInfoGen
from utils.IOService import WriteFrame

class Command(BaseCommand):
    help = '生成测试商品数据'

    def add_arguments(self, parser):
        parser.add_argument('--count', type=int, default=1000, help='要生成的商品数量')
        parser.add_argument('--category-count', type=int, default=50, help='商品类别数量')
        parser.add_argument('--threads', type=int, default=4, help='线程数量')

    def handle(self, *args, **options):
        product_count = options['count']
        category_count = options['category_count']
        thread_count = options['threads']

        generator = ProductInfoGen(product_count, category_count)
        wf = WriteFrame(generator)
        inserted_count = wf.thread_insert(thread_count)

        self.stdout.write(
            self.style.SUCCESS(f'成功生成并插入 {inserted_count} 条商品记录')
        )